import 'package:flutter/cupertino.dart';

import '../../../../pojo/ImPojo.dart';
import '../../../../util/ImConstant.dart';
import '../../../bloc/MessageListCubit.dart';
import 'AudioMessagePane.dart';
import 'ChatMessagePane.dart';
import 'FileMessagePane.dart';
import 'ImageMessagePane.dart';
import 'RichTextMessagePane.dart';
import 'TextMessagePane.dart';
import 'VideoMessagePane.dart';

class MessagePane extends StatelessWidget {

  final WrapImMessage wrapMessage;

  const MessagePane({ required this.wrapMessage, super.key});

  @override
  Widget build(BuildContext context) {
    if (wrapMessage.message.messageType == ImMessageType.Text) {
      return TextMessagePane(wrapMessage: wrapMessage);
    } else if (wrapMessage.message.messageType == ImMessageType.RichText) {
      return RichTextMessagePane(wrapMessage: wrapMessage,);
    } else if (wrapMessage.message.messageType == ImMessageType.Chat) {
      return ChatMessagePane(wrapMessage: wrapMessage);
    } else if (wrapMessage.message.messageType == ImMessageType.Image) {
      return ImageMessagePane(wrapMessage: wrapMessage);
    } else if (wrapMessage.message.messageType == ImMessageType.File) {
      return FileMessagePane(wrapMessage: wrapMessage);
    } else if (wrapMessage.message.messageType == ImMessageType.Audio) {
      return AudioMessagePane(wrapMessage: wrapMessage);
    } else if (wrapMessage.message.messageType == ImMessageType.Video) {
      return VideoMessagePane(wrapMessage: wrapMessage);
    } else {
      return TextMessagePane(wrapMessage: wrapMessage);
    }
  }

}

class MessageRefPane extends StatelessWidget {

  final ImMessage message;
  final MessageRefParam param;

  const MessageRefPane({ required this.message, required this.param, super.key});

  @override
  Widget build(BuildContext context) {
    message.init();
    if (message.messageType == ImMessageType.Text) {
      return TextMessageRefPane(message: message, param: param,);
    } else if (message.messageType == ImMessageType.RichText) {
      return RichTextMessageRefPane(message: message, param: param,);
    } else if (message.messageType == ImMessageType.Chat) {
      return ChatMessageRefPane(message: message, param: param,);
    } else if (message.messageType == ImMessageType.Image) {
      return ImageMessageRefPane(message: message, param: param,);
    } else if (message.messageType == ImMessageType.File) {
      return FileMessageRefPane(message: message, param: param,);
    } else if (message.messageType == ImMessageType.Audio) {
      return AudioMessageRefPane(message: message, param: param);
    } else if (message.messageType == ImMessageType.Video) {
      return VideoMessageRefPane(message: message, param: param);
    } else {
      return TextMessageRefPane(message: message, param: param,);
    }
  }

}

class MessageRefParam {
  int maxLines = 2;
  bool hasPrefix = false;
  double refMaxLength = 200;
  double fontSize;
  double iconSize;

  MessageRefParam({ this.maxLines = 2, this.hasPrefix = false, this.refMaxLength = 200,
    this.fontSize = ImConstant.IM_DEFAULT_SIZE, this.iconSize = 18.5
  });
}